﻿using ParkSaleForAdmin.Data;
using System.Windows;

namespace ParkSaleForAdmin
{
    public abstract class BasicManagerWindow<T> : DatabaseWindows<T> where T : class, IBaseData<T>, new()
    {

        public override void DeleteResult(object obj)
        {
            if (obj != null)
            {
                var r = (int)obj;
                if (r == SuUserResponseInfo<int>.OK)
                {
                    UpdatePage(page);
                    MessageBox.Show("删除成功");

                }
                else
                {
                    MessageBox.Show($"删除失败,Code:{r}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("删除失败");
            }

        }

        public override void AppendResult(object obj)
        {
            if (obj != null)
            {
                var r = (int)obj;
                if (r == SuUserResponseInfo<int>.OK)
                {
                    UpdatePage(page);
                    MessageBox.Show("录入成功");

                }
                else
                {
                    MessageBox.Show($"录入失败，Code:{r}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("录入失败，网络错误", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        public override void ChangeResult(object obj)
        {
            if (obj != null)
            {
                var r = (int)obj;
                if (r == SuUserResponseInfo<int>.OK)
                {
                    UpdatePage(page);
                    MessageBox.Show("修改成功");
                }
                else
                {
                    MessageBox.Show($"修改失败，Code:{r}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }
    }
}
